package com.cv.platform.controller.platform.video;

import com.cv.framework.common.pojo.PageResult;
import com.cv.framework.common.pojo.Result;
import com.cv.platform.controller.platform.video.vo.CvVideoItemRespVO;
import com.cv.platform.controller.platform.video.vo.CvVideoItemTypeRespVO;
import com.cv.platform.controller.platform.video.vo.detail.CvVideoDetailRespVO;
import com.cv.platform.controller.platform.video.vo.menu.CvVideoMenuReqVO;
import com.cv.platform.controller.platform.video.vo.profile.CvVideoProfileReqVO;
import com.cv.platform.controller.platform.video.vo.profile.CvVideoUncollectedReqVO;
import com.cv.platform.controller.platform.video.vo.profile.CvVideoUncollectedRespVO;
import com.cv.platform.controller.platform.video.vo.video.CvVideoReqVO;
import com.cv.platform.controller.platform.video.vo.video.CvVideoSaveReqVO;
import com.cv.platform.service.video.CvVideoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import java.util.List;

import static com.cv.framework.common.pojo.Result.success;

/**
 * 视频平台 - 视频控制层
 *
 * @author Charles_XDXD
 */
@Tag(name = "视频平台 - 视频控制层")
@RestController
@RequestMapping("/platform/video")
public class CvVideoController {

    @Resource
    private CvVideoService cvVideoService;

    // ==================== 首页请求 ====================

    @GetMapping("hotList")
    @Operation(summary = "获取热门视频列表（视频平台 - 首页）")
    @PermitAll
    public Result<List<CvVideoItemRespVO>> getVideoHotRecommend() {
        return success(cvVideoService.getVideoHotRecommend());
    }

    @GetMapping("allVideoHotTypeList")
    @Operation(summary = "获取热门视频分类列表（视频平台 - 首页）")
    @PermitAll
    public Result<List<CvVideoItemTypeRespVO>> getVideoTypeHotRecommend() {
        return success(cvVideoService.getVideoTypeHotRecommend());
    }

    // ==================== 用户主页请求 ====================

    @GetMapping("getUserProfileVideoList")
    @Operation(summary = "获取用户主页视频列表（视频平台 - 用户主页）")
    @PermitAll
    public Result<PageResult<CvVideoItemRespVO>> getUserProfileVideoList(CvVideoProfileReqVO reqVO) {
        return success(cvVideoService.getUserVideoPage(reqVO));
    }


    // ==================== 视频页请求 ====================

    @GetMapping("detail")
    @Operation(summary = "获取视频详情（视频平台 - 视频页）")
    @PermitAll
    public Result<CvVideoDetailRespVO> getVideoDetail(Long videoId) {
        return success(cvVideoService.getVideoDetail(videoId, false));
    }

    @GetMapping("recommend")
    @Operation(summary = "获取视频推荐列表（视频平台 - 视频页）")
    @PermitAll
    public Result<List<CvVideoItemRespVO>> getVideoRecommend(Long videoId) {
        return success(cvVideoService.getRecommendVideoList(videoId));
    }

    // ==================== 筛选页请求 ====================

    @GetMapping("menu")
    @Operation(summary = "获取视频筛选条件（视频平台 - 筛选页）")
    @PermitAll
    public Result<PageResult<CvVideoItemRespVO>> getVideoMenu(CvVideoMenuReqVO reqVO) {
        return success(cvVideoService.getVideoPage(reqVO));
    }

    // ==================== 视频保存请求 ====================

    @PostMapping("save")
    @Operation(summary = "保存视频（视频平台 - 视频保存）")
    public Result<Long> saveVideo(@RequestBody CvVideoSaveReqVO reqVO) {
        return success(cvVideoService.saveVideo(reqVO));
    }

    @DeleteMapping("delete")
    @Operation(summary = "删除视频（视频平台 - 删除视频）")
    public Result<Void> deleteVideo(Long videoId) {
        cvVideoService.deleteVideo(videoId);
        return success();
    }

    @GetMapping("page")
    @Operation(summary = "获取视频列表（视频平台 - 视频管理页）")
    public Result<PageResult<CvVideoItemRespVO>> getVideoOperationPage(CvVideoReqVO reqVO) {
        return success(cvVideoService.getVideoOperationPage(reqVO));
    }

    @GetMapping("operationDetail")
    @Operation(summary = "获取视频详情（视频平台 - 视频管理页）")
    public Result<CvVideoDetailRespVO> getVideoOperationDetail(Long videoId) {
        return success(cvVideoService.getVideoOperationDetail(videoId));
    }

    // ==================== 视频合集 ====================
    
    @GetMapping("uncollected/page")
    @Operation(summary = "获取未收入合集的视频列表（视频平台 - 视频合集）")
    public Result<PageResult<CvVideoUncollectedRespVO>> getUncollectedVideoPage(CvVideoUncollectedReqVO reqVO) {
        return success(cvVideoService.getUncollectedVideoPage(reqVO));
    }
    
    @GetMapping("uncollectedAndCurrent/page")
    @Operation(summary = "获取未收入合集的视频列表以及被当前合集收入的视频列表（视频平台 - 视频合集）")
    public Result<PageResult<CvVideoUncollectedRespVO>> getUncollectedVideoPageAndCurrent(CvVideoUncollectedReqVO reqVO) {
        return success(cvVideoService.getUncollectedAndCurrent(reqVO));
    }
    
}
